<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<div id="{{paragraph.id}}_control" class="control" ng-show="!asIframe">
  <span>
    <span ng-show="paragraph.runtimeInfos.jobUrl.values.length == 1">
      <a href="{{paragraph.runtimeInfos.jobUrl.values[0]}}" target="_blank" style="text-decoration: none;"
         tooltip-placement="top" uib-tooltip="{{paragraph.runtimeInfos.jobUrl.tooltip}}" >
        <span class="fa fa-tasks"></span>
        {{paragraph.runtimeInfos.jobUrl.label}}
      </a>
    </span>
    <span class="dropdown" ng-show="paragraph.runtimeInfos.jobUrl.values.length > 1">
      <span style="cursor:pointer;color:#3071A9" tooltip-placement="top" uib-tooltip="{{paragraph.runtimeInfos.jobUrl.tooltip}}"
            data-toggle="dropdown" type="button">
        <span class="fa fa-tasks"></span>
        {{paragraph.runtimeInfos.jobUrl.label}}S
      </span>
      <ul class="dropdown-menu" role="menu" style="width:200px;z-index:1002">
        <li ng-class="{'option-disabled': !noteOperationsAllowed()}" ng-repeat="url in paragraph.runtimeInfos.jobUrl.values">
          <a href="{{url}}" target="_blank"><span class="fa fa-external-link-square"></span> Jobs #{{$index}}</a>
        </li>
      </ul>
    </span>
  </span>
  <span>
    {{paragraph.status}}
  </span>

  <span ng-if="paragraph.status === 'RUNNING' && paragraph.executor !== 'SPELL'">
    {{getProgress()}}%
  </span>

  <!-- Run / Cancel button -->
  <span ng-if="!revisionView">
    <span class="icon-control-play" style="cursor:pointer;color:#3071A9"
          tooltip-placement="top" uib-tooltip="Run this paragraph (Shift+Enter)"
          ng-click="runParagraphFromButton(getEditorValue())"
          ng-show="paragraph.status!='RUNNING' && paragraph.status!='PENDING' && paragraph.config.enabled"></span>
    <span class="icon-control-pause" style="cursor:pointer;color:#CD5C5C"
          tooltip-placement="top" uib-tooltip="Cancel (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+C)"
          ng-click="cancelParagraph(paragraph)"
          ng-show="paragraph.status=='RUNNING' || paragraph.status=='PENDING'"></span>
    <span ng-show="paragraph.runtimeInfos.jobUrl.length == 1">
      <a href="{{paragraph.runtimeInfos.jobUrl[0]}}" target="_blank"><span class="fa fa-tasks"></span> Spark job </a>
    </span>
    <span class="dropdown" ng-show="paragraph.runtimeInfos.jobUrl.length > 1">
      <span class="fa fa-tasks" style="cursor:pointer;color:#3071A9" tooltip-placement="top" uib-tooltip="Run this paragraph (Shift+Enter)"
          data-toggle="dropdown"
          type="button">  Spark Jobs
      </span>
      <ul class="dropdown-menu" role="menu" style="width:200px;z-index:1002">
         <li ng-class="{'option-disabled': !noteOperationsAllowed()}" ng-repeat="url in paragraph.runtimeInfos.jobUrl">
           <a href="{{url}}" target="_blank"><span class="fa fa-external-link-square"></span> Jobs #{{$index}}</a>
         </li>
      </ul>
    </span>
    <span class="{{paragraph.config.editorHide ? 'icon-size-fullscreen' : 'icon-size-actual'}}" style="cursor:pointer" tooltip-placement="top"
          uib-tooltip="{{(paragraph.config.editorHide ? 'Show' : 'Hide')}} editor (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+E)"
          ng-click="toggleEditor(paragraph)"></span>
    <span class="{{paragraph.config.tableHide ? 'icon-notebook' : 'icon-book-open'}}" style="cursor:pointer" tooltip-placement="top"
          uib-tooltip="{{(paragraph.config.tableHide ? 'Show' : 'Hide')}} output (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+O)"
          ng-click="toggleOutput(paragraph)"></span>
    <span class="dropdown navbar-right">
      <span class="icon-settings" style="cursor:pointer"
            data-toggle="dropdown"
            type="button">
      </span>

      <ul class="dropdown-menu dropdown-menu-right" role="menu" style="width:270px;z-index:1002">
        <li ng-controller="clipboardCtrl" ng-click="$event.stopPropagation()" style="text-align:center;margin-top:4px;">
          <a  ngclipboard
              ngclipboard-success="complete($event)"
              ngclipboard-error="clipError($event)"
              data-clipboard-text="{{paragraph.id}}"
              tooltip-placement="top"
              uib-tooltip="{{tooltip}}">
            <span>{{paragraph.id}}</span>
          </a>
        </li>
        <li role="separator" class="divider"></li>
        <li style="padding-top:8px"
            ng-if="paragraph.config.runOnSelectionChange == true || paragraph.config.runOnSelectionChange == false">
          <span ng-if="paragraph.config.runOnSelectionChange == true" class="fa fa-toggle-on shortcut-icon" style="padding:3px 8px 8px 20px"></span>
          <span ng-if="paragraph.config.runOnSelectionChange == false" class="fa fa-toggle-off shortcut-icon" style="padding:3px 8px 8px 20px"></span>Run on selection change
          <form style="display:inline; float:right">
            <input type="checkbox"
                   style="width:16px; margin-right:20px"
                   tooltip-placement="top" uib-tooltip="Even if you uncheck this, still can run the paragraph by pressing Enter"
                   ng-checked="{{paragraph.config.runOnSelectionChange}}"
                   ng-click="turnOnAutoRun(paragraph)"/>
          </form>
        </li>
        <li>
          <a ng-click="$event.stopPropagation()" class="dropdown"><span class="fa fa-arrows-h shortcut-icon"></span>Width
            <form style="display:inline; margin-left:5px; float:right">
              <select ng-model="paragraph.config.colWidth"
                      class="selectpicker"
                      ng-change="changeColWidth(paragraph, paragraph.config.colWidth)"
                      ng-options="col for col in colWidthOption"></select>
            </form>
          </a>
        </li>
        <li>
          <a ng-click="moveUp(paragraph)" ng-hide="$first"><span class="icon-arrow-up shortcut-icon"></span>Move up
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+K</span></a>
        </li>
        <li>
          <a ng-click="moveDown(paragraph)" ng-hide="$last"><span class="icon-arrow-down shortcut-icon"></span>Move down
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+J</span></a>
        </li>
        <li>
          <a ng-click="insertNew('below')"><span class="icon-plus shortcut-icon"></span>Insert new
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+B</span></a>
        </li>
        <li>
          <a ng-click="copyParagraph(getEditorValue())"><span class="fa fa-copy shortcut-icon"></span>Clone paragraph
            <span class="shortcut-keys">Ctrl+Shift+C</span></a>
        </li>
        <li>
          <!-- paragraph handler -->
          <a ng-click="hideTitle(paragraph)"
             ng-show="paragraph.config.title"><span class="fa fa-font shortcut-icon"></span>Hide title
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+T</span></a>
          <a ng-click="showTitle(paragraph)"
             ng-show="!paragraph.config.title"><span class="fa fa-font shortcut-icon"></span>Show title
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+T</span></a>
        </li>
        <li>
          <a ng-click="hideLineNumbers(paragraph)"
             ng-show="paragraph.config.lineNumbers"><span class="fa fa-list-ol shortcut-icon"></span>Hide line numbers
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+M</span></a>
          <a ng-click="showLineNumbers(paragraph)"
             ng-show="!paragraph.config.lineNumbers"><span class="fa fa-list-ol shortcut-icon"></span>Show line numbers
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+M</span></a>
        </li>
        <li>
          <a ng-click="toggleEnableDisable(paragraph)"><span class="icon-control-play shortcut-icon"></span>
            {{paragraph.config.enabled ? "Disable" : "Enable"}} run
            <span class="shortcut-keys">Ctrl+ {{ isMac ? 'Option' : 'Alt'}}+R</span></a>
        </li>
        <li>
          <a ng-click="goToSingleParagraph()"><span class="icon-share-alt shortcut-icon"></span>Link this paragraph
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+W</span></a>
        </li>
        <li>
          <a ng-click="clearParagraphOutput(paragraph)"><span class="fa fa-eraser shortcut-icon"></span>Clear output
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+L</span></a>
        </li>
        <li>
          <!-- remove paragraph -->
          <a ng-click="removeParagraph(paragraph)" ng-hide="$last"><span class="fa fa-times shortcut-icon"></span>Remove
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+D</span></a>
        </li>
      </ul>
    </span>
  </span>
</div>
